Use case: conversion by polling ¶
Description of usage ¶
|
Operation |
HAL1 |
HAL2 |
|---|---|---|
|
Start conversion |
Activate the ADC peripheral and start the conversion using:
|
Activate the ADC peripheral and start the conversion using
Note From this point, the ADC internal analog hardware is enabled, inducing a slight current consumption. Start the conversion with a trigger using:
Note The conversion trigger can be:
|
|
Calibration (optional) |
|
|
|
Wait for conversion completion |
Wait for ADC conversion completion using:
Note
For specific events (such as
|
Poll for conversion completion using:
Note
For specific events (such as
|
|
Retrieve conversion results |
Retrieve conversion results using:
|
Retrieve conversion results using:
|
|
Stop conversion |
Stop potential ongoing conversions and disable the ADC peripheral using:
|
If the conversion trigger is not a software start (from another peripheral, such as a timer), stop the conversion using:
Stop the ADC using
|
|
Loop for multiple iterations |
N/A |
Multiple iterations for starting and stopping conversions are possible. Warning
If multiple conversions are required, do not fully stop the ADC using the
|
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
|
Regular group use case while(1)
{
/* Start the ADC conversion */
HAL_ADC_Start(&hadc1);
/* Poll for the end of conversion */
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
/* Read the ADC value */
adcValue = HAL_ADC_GetValue(&hadc1);
}
/* Stop the ADC conversion */
HAL_ADC_Stop(&hadc1);
}
|
Regular group use case /* Start the ADC */
HAL_ADC_Start(&hadc1);
while(1)
{
/* Start the ADC conversion */
HAL_ADC_REG_StartConv(&hadc1);
/* Poll for the end of conversion */
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
/* Read the ADC value */
adcValue = HAL_ADC_GetValue(&hadc1);
}
/* Stop the ADC regular conversion */
HAL_ADC_REG_StopConv(&hadc1);
}
/* Stop the ADC */
HAL_ADC_Stop(&hadc1);
|
|
Injected group use case while(1)
{
/* Start the ADC injected conversion */
HAL_ADCEx_InjectedStart(&hadc1);
/* Poll for the end of injected conversion */
if (HAL_ADCEx_InjectedPollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
/* Read the ADC injected values */
injectedValue1 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_1);
injectedValue2 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_2);
}
/* Stop the ADC injected conversion */
HAL_ADCEx_InjectedStop(&hadc1);
}
|
Injected group use case /* Start the ADC */
HAL_ADC_Start(&hadc1);
while(1)
{
/* Start the ADC conversion */
HAL_ADC_INJ_StartConv(&hadc1);
/* Poll for the end of injected conversion */
if (HAL_ADC_INJ_PollForConv(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
/* Read the ADC injected values */
injectedValue1 = HAL_ADC_INJ_GetValue(&hadc1, 1);
injectedValue2 = HAL_ADC_INJ_GetValue(&hadc1, 2);
}
/* Stop the ADC injected conversion */
HAL_ADC_INJ_StopConv(&hadc1);
}
/* Stop the ADC */
HAL_ADC_Stop(&hadc1);
|
Key changes ¶
The split of the activate and start conversion functions.
The split of the disable and stop conversion functions.


